﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>日程提醒</title>
  <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.css?v=4.3.0" rel="stylesheet">
    <link href="/JqueryPlug/zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <link href="/CSS/V3/animate.css" rel="stylesheet">
    <link href="/CSS/V3/style.css?v=2.2.0" rel="stylesheet">
    <link href="/CSS/V3/BaseClassV3.css" rel="stylesheet" />
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/JqueryPlug/laypage/laypage.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <script src="/CSS/V3/jquery-ui.custom.min.js"></script>
    <link href="/CSS/V3/fullcalendar/fullcalendar.css" rel="stylesheet" />
    <link href="/CSS/V3/fullcalendar/fullcalendar.print.css" rel="stylesheet" />
    <script src="/CSS/V3/fullcalendar/fullcalendar.min.js"></script>
    <script src="/JqueryPlug/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
    <script src="/JqueryPlug/zTree_v3/js/jquery.ztree.excheck-3.5.min.js"></script>

    <script>
        var model = avalon.define({
            $id: "TXSX",
            queryuser: ComFunJS.getnowuser(),
            username: ComFunJS.getnowuser(),
            Type: "0",
            Content: "",
            selType: "0",
            selContent: "",
            CommonData: [],
            menutype: "-1",
            ShowType:"2",
            AddTXSX: function () {
                parent.ComFunJS.winviewform("/View/APPBaseView/APP_ADD_WF.html?FormCode=TXSX&r=" + Math.random(), "添加数据", "1000", "");
            },
            fnqueryuser: function (item) {
                if (item) {
                    model.queryuser = item;
                    model.CommonData.clear();
                    model.GetTXData();
                }
            },
            setshowtype: function (t) {
                $(".stbtn button").removeClass("btn-primary").addClass("btn-default");
                $(this).removeClass("btn-default").addClass("btn-primary");

                model.ShowType = t;
                model.GetTXData();
            },
            GetTXData: function () {
                if (model.ShowType == "1") {
                    

                    $.getJSON('/API/FTAPI.ashx?Action=GETTXSXDATA', { P1: model.Type, p: 1, Content: model.Content, b: model.menutype, "QUSER": model.queryuser }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            model.CommonData.clear();
                            model.CommonData = resultData.Result;
                            model.selType = model.Type;
                            model.selContent = model.Content;
                            if (parseInt(resultData.Result1) > 0) {
                                $("#pageDiv").show();
                                laypage({
                                    cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                                    pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / 8), //通过后台拿到的总页数
                                    curr: 1, //初始化当前页
                                    jump: function (e) { //触发分页后的回调
                                        if (model.selType != model.Type || model.selContent != model.Content) {
                                            e.curr = 1;
                                        }
                                        $.getJSON('/API/FTAPI.ashx?Action=GETTXSXDATA', { P1: model.Type, p: e.curr, Content: model.Content, b: model.menutype, "QUSER": model.queryuser }, function (resultData) {
                                            model.CommonData.clear();
                                            model.CommonData = resultData.Result;
                                            model.selType = model.Type;
                                            model.selContent = model.Content;
                                        })
                                    }
                                });
                            }
                            else {
                                $("#pageDiv").hide();
                            }
                        }
                    })
                } else if (model.ShowType == "2") {
                    $('#calendar').html("");
                    $('#calendar').fullCalendar({
                        header: {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'month,basicWeek'  //basicDay
                        },
                        monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                        firstDay: "1",
                        events: function (start, end, callback) {
                            var st = $.fullCalendar.formatDate(start, "yyyy-MM-dd");
                            var ed = $.fullCalendar.formatDate(end, "yyyy-MM-dd");

                            $.getJSON("/API/FTAPI.ashx?action=GETTXSXDATA_BY", { "start": st, "end": ed, P1: model.Type, "QUSER": "'" + model.queryuser + "'" }, function (r) {
                                if (r.Result.length > 0) {
                                    callback(r.Result);
                                }
                            })
                        },
                        eventClick: function (calEvent, jsEvent, view) {

                            var id = calEvent.ID;
                            parent.ComFunJS.winviewform("/View/APPBaseView/APP_ADD_WF.html?FormCode=TXSX&ID=" + id + "&pageType=view", "查看数据", "1000", "");
                            

                        }

                    });

                }
            },
            EditTXSX: function (Id) {

                parent.ComFunJS.winviewform("/View/APPBaseView/APP_ADD_WF.html?FormCode=TXSX&ID=" + Id+"&r=" + Math.random(), "修改数据", "1000", "");
            },
            DelTXSX: function (scel, event) {

                event.stopPropagation();
                parent.ComFunJS.winconfirm('你确定要删除吗？', function () {
                    $.post("/API/FTAPI.ashx", { Action: "DELTXSX", P1: scel.ID }, function (result) {
                        var jsonresult = $.parseJSON(result)
                        if ($.trim(jsonresult.ErrorMsg) == "") {
                            model.CommonData.remove(scel);
                            parent.ComFunJS.winsuccess('删除成功');
                        }

                    });
                }, function () { })

                //if (confirm("确定要删除么？")) {
                //    $.post("/API/FTAPI.ashx", { Action: "DELTXSX", P1: scel.ID }, function (result) {
                //        var jsonresult = $.parseJSON(result)
                //        if ($.trim(jsonresult.ErrorMsg) != "") {
                //            ComFunJS.winwarning(jsonresult.ErrorMsg);
                //        } else {
                //            model.CommonData.remove(scel);
                //        }
                //    })
                //}
            },
            LB: function () {
                model.Type = $(this).attr("vl");
                if ($(this).hasClass("btn-primary")) {
                    model.GetTXData();
                }
                else {
                    $(".leibie").removeClass("btn-primary");
                    $(".leibie").addClass("btn-white");
                    $(this).removeClass("btn-white");
                    $(this).addClass("btn-primary");
                    model.GetTXData();
                }
            },
            IsShowTR: false,
            getMenu: function () {
                var setting = {
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPId: 0
                        }
                    },
                    view: {
                        showLine: false
                    },
                    callback: {
                        onClick: model.zTreeOnClick
                    }
                };
                $.ajax({
                    type: "GET",
                    url: "/API/SZHLAPI.ashx",
                    dataType: "html",
                    data: { "Action": "GETALLBMUSERLIST" },
                    success: function (msg) {
                        if (JSON.parse(msg).Result) {
                            model.IsShowTR = true;
                        }
                        zTreeObj = $.fn.zTree.init($("#tree"), setting, eval(JSON.parse(msg).Result));
                    }
                });
            },
            zTreeOnClick: function (event, treeId, treeNode) {
                model.queryuser = "";
                model.CommonData.clear();
                if (treeNode.isUser) {
                    model.queryuser = treeNode.id;
                } else {
                    model.menutype = treeNode.id;
                    if (treeNode.children.length > 0 && treeNode.children[0].isUser) {

                        $(treeNode.children).each(function (i, user) {
                            model.queryuser += user.id + ",";
                        })
                        model.queryuser = model.queryuser.substring(0, model.queryuser.length - 1);
                    }
                }
                model.GetTXData();
            }

        });
        avalon.ready(function () {
            ComFunJS.initsetajax();
            model.GetTXData();
            model.getMenu();



        })
        function txsz(str) {
            var html1 = '';
            var html2 = '';
            var html3 = '';
            var html = '';

            switch (str.Type) {
                case "0": html1 = '短信和微信'; break;
                case "1": html1 = '短信'; break;
                case "2": html1 = '微信'; break;
            }

            switch (str.TXType) {
                case "0": html2 = '立即发送'; break;
                case "1": html2 = '仅一次,' + str.Date + ' ' + str.Hour + ':' + str.Minute; break;
                case "2": html2 = '每个工作日的' + str.Hour + ':' + str.Minute; break;
                case "3": html2 = '每天的' + str.Hour + ':' + str.Minute; break;
                case "4": html2 = '每周' + str.Days + '的' + str.Hour + ':' + str.Minute; break;
            }
            if (!(str.TXType == "0" || str.TXType == "1")) {
                switch (str.CFType) {
                    case "1": html3 = ',无结束时间'; break;
                    case "2": html3 = ',' + str.CFCount + '次后结束,已经执行' + (str.ZXCount?str.ZXCount:'0') + '次'; break;
                    case "3": html3 = ',结束时间：' + (str.CFJZDate?str.CFJZDate.substring(0, 10):''); break;
                }
            }
            html = html1 + '提醒,' + html2 + html3;
            return html;
        }
    </script>
</head>
<body class="gray-bg" ms-controller="TXSX">

    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-3">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="file-manager">
                            <div class="hr-line-dashed"></div>
                            <button class="btn btn-primary btn-block" ms-click="AddTXSX()">添加提醒</button>
                            <div class="hr-line-dashed"></div>
                            <h4>类型</h4>
                            <button class="btn btn-white btn-sm leibie" ms-attr-vl="" ms-click="LB()" type="button">全部</button>
                            <button class="btn btn-primary btn-sm leibie" ms-attr-vl="0" ms-click="LB()" type="button">正在进行</button>
                            <button class="btn btn-white btn-sm leibie" ms-attr-vl="1" ms-click="LB()" type="button">已结束</button>
                            <div class="clearfix"></div>

                             <h4 class="tag-title"><a href="APP_TXSX.html">我的提醒</a></h4>
                            <h4 class="tag-title" ms-if="model.IsShowTR">他人提醒</h4>

                            <ul id="tree" ms-if="model.IsShowTR" class="ztree"></ul>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-9">
                <div class="ibox">
                    <div class="box" style="margin-bottom:15px;">

                        <div class="pull-right mail-search">
                            <div class="input-group">
                                <input type="text" class="form-control input-sm" ms-duplex="Content" name="search" placeholder="输入内容和提醒人用户名查询">
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary" ms-click="GetTXData()">
                                        搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                        <h2>
                            提醒事项
                        </h2>
                        <div class="mail-tools tooltip-demo m-t-md">
                            <div class="btn-group pull-right">
                                <div id="pageDiv" class="text-center"></div>
                            </div>
                             <div class="input-group-btn stbtn">
                                   
                                  <button type="button" class="btn btn-sm btn-primary" ms-click="setshowtype('2')">
                                        日历
                                    </button>
                                  <button type="button" class="btn btn-sm btn-default" ms-click="setshowtype('1')">
                                        列表
                                    </button>
                                </div>

                            
                            <div class="clearfix"></div>
                        </div>

                    </div>

                </div>
                <div class="full-height-scroll">
                    <div class="table-responsive" ms-if="ShowType=='1'">
                        <table class="table  table-hover">
                            <thead>
                                <tr>
                                    <th>状态</th>
                                    <th>提醒人</th>
                                    <th>提醒内容</th>
                                    <th>提醒设置</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ms-repeat-el="CommonData">
                                    <td>
                                        <a data-toggle="tab" href="#contact-1" class="client-link">{{el.Status=='1'?'已结束':'正在进行'}}</a>
                                    </td>
                                    <td>
                                        <span style="margin-right:10px" ms-repeat-user="el.TXUser.split(',')">{{ComFunJS.convertuser(user) }}</span>
                                    </td>
                                    <td>
                                        {{el.TXContent}}
                                    </td>
                                    <td>{{txsz(el)}}</td>

                                    <td class="client-status">
                                        <!-- <a class=" btn btn-white btn-xs" ms-click="ViewDT(el.ID)"><i class="fa fa-search"></i> 查看 </a>-->
                                        <a class=" btn btn-primary btn-xs" ms-click="EditTXSX(el.ID)" ms-if="el.CRUser==username"><i class=" fa fa-pencil"></i> 编辑 </a>
                                        <a class="btn btn-danger btn-xs" ms-click="DelTXSX(el,event)" ms-if="el.CRUser==username"><i class="fa fa-trash-o"></i> 删除 </a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                     <div id="calendar" ms-if="ShowType=='2'"></div>

                </div>
            </div>

        </div>
    </div>
</body>
</html>
